sudo: command not found - damaged PATH file in terminal. How to restore?

Hi, I was editing one of the PATH variables holding file (~/.bash_profile or somewhere deeper), something went wrong and now terminal can't find any program (i.e. nano) or use sudo.


The problem is that to edit that file I need to be admin, but I can't use sudo. Any ideas?

Posted on Jul 19, 2014 6:51 AM

Reply
5 replies

Jul 19, 2014 10:42 AM in response to Limmor1

Back up all data.


Select

Shell ▹ New Command

from the Terminal menu bar. Uncheck the box marked

Run command inside a shell

if checked.

Copy and paste the following line into the text box that opens, then press return:

mkdir disabled_shell_files


Close the Terminal window that opens. Repeat with this line:

mv .profile .bash_history .bash_profile .bashrc .inputrc disabled_shell_files

Your old shell initialization and history files will be saved in a directory named "disabled_shell_files" at the top level of your home directory. It's normal that some of these files will not exist, and therefore you will get some "no such file" errors.

Close the window, open a new one, and test.

Jul 21, 2014 5:11 AM in response to Linc Davis

Thank Linc,


I have tried your suggestion and it pointed me to the right direction. The suggested method, however created no files in /disabled_shell_files, which meant I have my paths set up somewhere else (?). I didn't know you can run commands outside shell, which worked with sudo. So I checked my /etc/profile and found the faulty line. I was able to remove it with sudo nano /etc/profile and it fixed the problem!


Thanks

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

sudo: command not found - damaged PATH file in terminal. How to restore?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.